package org.tulkas.selector.pattern;

import org.tulkas.selector.Filter;
import org.w3c.dom.Element;

/**
 * @author <a href="mailto:tulkas.web@gmail.com">Tulkas</a>
 *
 */
public class Tag implements Filter {

	private String tag = null;

	public Tag(String tag) {
		if (tag == null) {
			throw new NullPointerException("Tag name can't be null!");
		}
		this.tag = tag;
	}

	/* (non-Javadoc)
	 * @see org.tulkas.selector.Filter#getPriority()
	 */
	@Override
	public int getPriority() {
		return PRIORITY_TAG;
	}

	/* (non-Javadoc)
	 * @see org.tulkas.selector.Filter#matches(org.w3c.dom.Element)
	 */
	@Override
	public boolean matches(Element element) {
		return this.tag.equalsIgnoreCase(element.getTagName());
	}

	@Override
	public String toString() {
		return new StringBuffer().append("<").append(tag).append(">")
				.toString();
	}
}
